package com.smart.seven.aop.noproxy;

/**
 * 性能监视实现类
 *
 * @author junrui.wang
 * @create 2018/7/24
 */
public class PerformanceMonitor {

    //通过ThreadLocal保存与调用线程相关的性能监视信息（ThreadLocal是将非线程安全类改造成线程安全类的“法宝”）
    private static ThreadLocal<MethodPerformance> performanceRecord =
            new ThreadLocal<MethodPerformance>();

    //启动对某一个目标方法的性能监视
    public static void begin(String method){
        System.out.println("begin monitor...");
        MethodPerformance methodPerformance = new MethodPerformance(method);
        performanceRecord.set(methodPerformance);
    }

    public static void end(){
        System.out.println("end monitor...");
        MethodPerformance methodPerformance = performanceRecord.get();
        //打印出方法性能监视的结果信息
        methodPerformance.printPerformance();
    }
}
